/**
 * @param {string} s
 * @param {string} t
 * @return {boolean}
 */
var isAnagram = function (s, t) {
    if(s.length!==t.length)
        return false;
    //排序在比较数组是否一致
    const sArr = Array.from(s);
    sArr.sort();

    const tArr = Array.from(t);
    tArr.sort();

    for (let i = 0; i < sArr.length; i++) {
        if (sArr[i] !== tArr[i]) {
            return false;
        }
    }
    return true;
};

var isAnagram = function (s, t) {
    if(s.length!==t.length)
        return false;
    //排序在比较数组是否一致 简化版
    //变成字节数组排序然后再转为string比较 相同则一致。
    return s.length === t.length && [...s].sort().join('') === [...t].sort().join('')

};

var isAnagram = function(s, t) {
    if (s.length !== t.length) {
        return false;
    }
    const table = new Array(26).fill(0);
    for (let i = 0; i < s.length; ++i) {
        table[s.codePointAt(i) - 'a'.codePointAt(0)]++;
    }
    for (let i = 0; i < t.length; ++i) {
        table[t.codePointAt(i) - 'a'.codePointAt(0)]--;
        if (table[t.codePointAt(i) - 'a'.codePointAt(0)] < 0) {
            return false;
        }
    }
    return true;
};
console.log(isAnagram("anagram", "nagaram"));